package self_Exception;

public class Process {
	private StartData data;//入参
	private Result result;//处理结果
	
	public Process(){
		this(new StartData());
	}
	
	public Process(StartData data){
		this.result = new Result();
		this.data = data;
	}
	
	public Result go_do(){
		try {
			this.do_first();
			this.do_2();
			this.do_3();
			this.do_last();
		} catch (My_Exception e) {
			// TODO: handle exception
			this.result.setCode(e.getCode());
			this.result.setMsg(this.result.getMsg()+e.getMsg());
			this.result.setData("校验未通过，无处理数据");
		} finally {
			System.out.println("over");
		}
		//System.out.println("over1");
		return this.result;
		//System.out.println("over");
		//return this.result;
	}
	
	private void do_first(){
		System.out.println("请求的处理code为："+this.data.getCode());
		if("0001".equals(this.data.getCode())){
			this.result.setMsg("请求'0001'");
		}
		return;
	}
	private void do_2() throws My_Exception{
		if((Integer)this.data.getData()<18){
			error("90001","处理失败,年龄未满18周岁");
		}
	}
	private void do_3(){
		System.out.println("do_3");
	}
	private void do_last(){
		System.out.println("do_last");
		this.result.setCode("00000");
		this.result.setMsg("成功");
		this.result.setData(1);
	}
	
	
	
	private void error(String code, String msg) throws My_Exception {
		throw new My_Exception(code,msg);
	}
}
